package com.selfdriving.activity;

import com.selfdriving.R;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class HomeActivity extends ActivityGroup  implements OnCheckedChangeListener{
	private FrameLayout container = null;
	private Intent intent1;
	private Intent intent2;
	private Intent intent3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		intent1 = new Intent(HomeActivity.this, ActivityNoticeActivity.class);
		intent2 = new Intent(HomeActivity.this, BestFeatureActivity.class);
		intent3 = new Intent(HomeActivity.this, FeatureJoinActivity.class);
		init();
	}

	public void init() {
		container = (FrameLayout) findViewById(R.id.tabcontent);
		RadioButton btnModule1 = (RadioButton) findViewById(R.id.tab_item_1);
		btnModule1.setOnCheckedChangeListener(this);
		RadioButton btnModule2 = (RadioButton) findViewById(R.id.tab_item_2);
		btnModule2.setOnCheckedChangeListener(this);
		RadioButton btnModule3 = (RadioButton) findViewById(R.id.tab_item_3);
		btnModule3.setOnCheckedChangeListener(this);
		btnModule1.setChecked(true);
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			container.removeAllViews();
			switch (buttonView.getId()) {
			case R.id.tab_item_1:
				container.addView(getLocalActivityManager().startActivity("1",
						intent1).getDecorView());
				break;
			case R.id.tab_item_2:
				container.addView(getLocalActivityManager().startActivity("2",
						intent2).getDecorView());
				break;
			case R.id.tab_item_3:
				container.addView(getLocalActivityManager().startActivity("3",
						intent3).getDecorView());
				break;
			default:
				break;
			}
		}
	}
}
